package ca.seia.comp6521.a1.io;

import static org.junit.Assert.*;

import java.io.FileNotFoundException;
import java.util.ArrayList;

import org.junit.Test;

public class DataFileReaderTestCase {
	
	
	@Test
	public void testReadNextIntegers12Ints(){
		
		String absolutefilePath = "C:/comp6521_files/phase2_ut_12ints.dat";
		
		try {
			DataFileReader dataFileReader = new DataFileReader(absolutefilePath);
			
			ArrayList<Integer> actualIntegers = new ArrayList<>();
			boolean isEndOfFileReached = false;
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(4, actualIntegers.size());
			assertEquals(false, isEndOfFileReached);
			
			assertEquals(1, actualIntegers.get(0).intValue());
			assertEquals(2, actualIntegers.get(1).intValue());
			assertEquals(3, actualIntegers.get(2).intValue());
			assertEquals(4, actualIntegers.get(3).intValue());
			
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(8, actualIntegers.size());
			assertEquals(false, isEndOfFileReached);
			
			assertEquals(5, actualIntegers.get(4).intValue());
			assertEquals(6, actualIntegers.get(5).intValue());
			assertEquals(7, actualIntegers.get(6).intValue());
			assertEquals(8, actualIntegers.get(7).intValue());
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(12, actualIntegers.size());
			assertEquals(false, isEndOfFileReached);
			
			assertEquals(9, actualIntegers.get(8).intValue());
			assertEquals(10, actualIntegers.get(9).intValue());
			assertEquals(11, actualIntegers.get(10).intValue());
			assertEquals(12, actualIntegers.get(11).intValue());
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(12, actualIntegers.size());
			assertEquals(true, isEndOfFileReached);
			
		} catch (FileNotFoundException e) {
			fail("Error While Creating Phase2 Reader");
		}
	}

	
	@Test
	public void testReadNextIntegers14Ints(){
		
		String absolutefilePath = "C:/comp6521_files/phase2_ut_14ints.dat";
		
		try {
			DataFileReader dataFileReader = new DataFileReader(absolutefilePath);
			
			ArrayList<Integer> actualIntegers = new ArrayList<>();
			boolean isEndOfFileReached = false;
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(4, actualIntegers.size());
			assertEquals(false, isEndOfFileReached);
			
			assertEquals(1, actualIntegers.get(0).intValue());
			assertEquals(2, actualIntegers.get(1).intValue());
			assertEquals(3, actualIntegers.get(2).intValue());
			assertEquals(4, actualIntegers.get(3).intValue());
			
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(8, actualIntegers.size());
			assertEquals(false, isEndOfFileReached);
			
			assertEquals(5, actualIntegers.get(4).intValue());
			assertEquals(6, actualIntegers.get(5).intValue());
			assertEquals(7, actualIntegers.get(6).intValue());
			assertEquals(8, actualIntegers.get(7).intValue());
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(12, actualIntegers.size());
			assertEquals(false, isEndOfFileReached);
			
			assertEquals(9, actualIntegers.get(8).intValue());
			assertEquals(10, actualIntegers.get(9).intValue());
			assertEquals(11, actualIntegers.get(10).intValue());
			assertEquals(12, actualIntegers.get(11).intValue());
			
			isEndOfFileReached = dataFileReader.readNextIntegers(4, actualIntegers);
			assertEquals(14, actualIntegers.size());
			assertEquals(true, isEndOfFileReached);
			
			assertEquals(13, actualIntegers.get(12).intValue());
			assertEquals(14, actualIntegers.get(13).intValue());
			
			
		} catch (FileNotFoundException e) {
			fail("Error While Creating Phase2 Reader");
		}
	}
	
}
